﻿using Prism.Commands;
using Prism.Regions;
using Prism.Services.Dialogs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;

namespace Zhy.PrismRegion.NewRegion.ViewModels
{
    public class DialogViewModel :
        IDialogAware  // Prism框架弹出需要实现这个接口，不实现的话会报错的
    {
        public string Title => "";

        public event Action<IDialogResult> RequestClose;

        public bool CanCloseDialog()
        {
            return true;
        }

        public void OnDialogClosed()
        {

        }

        public void OnDialogOpened(IDialogParameters parameters)
        {

        }

        /// <summary>
        /// 显示区域导航子页面按钮
        /// </summary>
        public DelegateCommand ShowViewCommand { get; set; }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="regionManager">区域子页面管理器注入</param>
        public DialogViewModel(IRegionManager regionManager)
        {
            ShowViewCommand = new DelegateCommand(() =>
            {
                var region = regionManager.Regions["DialogRegion"];
                var view = region.Views.FirstOrDefault(v => v.GetType().Name == "SubView");
                // 参数1：区域名称 参数2：子页面名称 参数3：要向子页面传递的参数
                regionManager.RequestNavigate("DialogRegion", "SubView");  // 打开SubView
            });
        }
    }
}
